<?php
/*
 * Hooligan - A sports facilities management software
 * Copyright (C) 2009/2010 Gianluca Bargelli <g.bargelli@gmail.com>,
 * Andrea Biocco <abiocco@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Project home: <http://code.google.com/hooligan>
 *
*/
/**
 * \brief Descrizione breve della classe.
 *
 * Descrizione dettagliata della classe.
 *
 * @author bargio
 */
class Model_User
{
    private $username;
    private $role;

    function __construct($username)
    {
        $this->username=$username;
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function setUsername($username)
    {
        $this->username=$username;
    }

    public function getRole()
    {
        return $this->role;
    }

    public function setRole($role)
    {
        $this->role=$role;
    }

    public function userRole()
    {
        $userRole;
        $conn=new Model_Db(new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE));
        $joinCliente="SELECT * from Utente, Cliente
        WHERE (Utente.username='{$this->username}') 
        AND (Utente.username=Cliente.Utente_username) LIMIT 1;";

        $joinGestore="SELECT * from Utente, Gestore
        WHERE (Utente.username='{$this->username}')
        AND (Utente.username=Gestore.Utente_username) LIMIT 1;";

        $joinAdmin="SELECT * from Utente, Amministratore
        WHERE (Utente.username='{$this->username}')
        AND (Utente.username=Amministratore.Utente_username) LIMIT 1;";

        $resultCliente=$conn->eseguiQuery($joinCliente);
        $resultGestore=$conn->eseguiQuery($joinGestore);
        $resultAdmin=$conn->eseguiQuery($joinAdmin);
        
        if (mysqli_num_rows($resultCliente)!=0)
        {
           $userRole="cliente";
        }
        else if(mysqli_num_rows($resultGestore)!=0)
        {
           $userRole="gestore";
        }
        else if(mysqli_num_rows($resultAdmin)!=0)
        {
           $userRole="admin";
        }
        return $userRole;
    }
}
?>
